(function($) {
	var data = [ {
		str : navigator.userAgent,
		sub : 'Chrome',
		ver : 'Chrome',
		name : 'chrome'
	}, {
		str : navigator.vendor,
		sub : 'Apple',
		ver : 'Version',
		name : 'safari'
	}, {
		prop : window.opera,
		ver : 'Opera',
		name : 'opera'
	}, {
		str : navigator.userAgent,
		sub : 'Firefox',
		ver : 'Firefox',
		name : 'firefox'
	}, {
		str : navigator.userAgent,
		sub : 'MSIE',
		ver : 'MSIE',
		name : 'ie'
	} ];
	for ( var n = 0; n < data.length; n++) {
		if ((data[n].str && (data[n].str.indexOf(data[n].sub) != -1))
				|| data[n].prop) {
			var v = function(s) {
				var i = s.indexOf(data[n].ver);
				return (i != -1) ? parseInt(s.substring(i + data[n].ver.length
						+ 1)) : '';
			};
			$('html').addClass(
					data[n].name + ' ' + data[n].name + v(navigator.userAgent)
							|| v(navigator.appVersion));
			break;
		}
	}
})(jQuery);
function gup(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if (results == null)
		return "";
	else
		return results[1];
}

$(document).ready(function() {
	scroller();
	scrollersmall();
	
	$('.gallery .image img').error(function(){
		console.log($(this).attr('src'));
		$(this).attr('src','css/skin1/img/blank.jpg');
		cyclic : true
	});
	
	$('.gallery a[rel=fancybox].img').fancybox({
		cyclic : true
	});
	$('a[rel=fancybox].img').fancybox({
	});	
	
	$('#musli').musli();
	
	var fotourl = $("#foto-url");
	if(fotourl){
		fotourl=fotourl.val();
		if(fotourl && fotourl.length > 0){
		$.ajax({
			url: fotourl,
			type: "POST",
			}).success(function(result) {
				if(result && result.length > 0) {
	        		$("#carousel-wrapper").html(result);
		        	$('#carousel').carouFredSel({circular: false,scroll: {duration: 1000}});
				}
	    });
		}
	}
});


function scroller() {
	$('#menu ul li.menu-opt a[href*=#]').click(function(elem,ev) {
	    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	      var $target = $(this.hash);
	      $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
	      if ($target.length) {
	        var targetOffset = $target.offset().top-80;
	        console.log(targetOffset);
	        $('html,body').animate({scrollTop: targetOffset}, 1000);
	        $(this).find("a").each(function(el){console.log($(el).html());$(el).removeClass("active");});
	        $(this).parent().siblings().each(function(el){$(this).removeClass("active");});
	        $(this).parent().addClass("active");
	       return false;
	      }
	    }
	  });
}

function scrollersmall() {
	$('#select-menu option[value*=#]').click(function(elem,ev) {console.log("click");
	    //if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	      var $target = $(this.value);
	      console.log('target ' +$target);
	      $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
	      if ($target.length) {
	        var targetOffset = $target.offset().top-80;
	        console.log(targetOffset);
	        $('html,body').animate({scrollTop: targetOffset}, 1000);
	       return false;
	      }
	    //}
	  });
}




